package com.example.mapper;

import com.example.pojo.Area;
import com.example.pojo.AreaLevel;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface AreaMapper {

    List<Area> selectByArea(Area area);

    List<Area> selectAreasByCampusSuffix(String campusSuffix);

    int reduceDormitoryAreaName(@Param("areaNameBefore") String areaNameBefore,@Param("areaName") String areaName);

    int reduceDormitoryAreaNameByCampus(@Param("campusSuffix") String campusSuffix,@Param("areaNameSuffix") String areaNameSuffix,@Param("areaList") List<Area> areaList);

    @Select("select * from t_area where area_name=#{areaName} and area_level=#{areaLevel} and region_divide=#{regionDivide} and del_flag=0")
    @ResultMap("AreaResult")
    Area selectByAreaNameAndAreaLevelAndReg(@Param("areaName") String areaName,@Param("areaLevel") Integer areaLevel,@Param("regionDivide") Integer regionDivide);

    @Select("select * from t_area where area_name like concat(#{areaNamePrefix},'%') and area_level=#{areaLevel} and region_divide=#{regionDivide} and del_flag=0")
    @ResultMap("AreaResult")
    List<Area> selectByAreaNamePrefixAndAreaLevelAndReg(@Param("areaNamePrefix") String areaNamePrefix,@Param("areaLevel") Integer areaLevel,@Param("regionDivide") Integer regionDivide);

    @Select("select * from t_area where id=#{id}")
    @ResultMap("AreaResult")
    Area selectById(Integer id);

    @Select("select * from t_area where area_name=#{areaName} and parent_id=#{parentId} and del_flag=0")
    @ResultMap("AreaResult")
    Area selectByAreaNameAndParentId(@Param("areaName") String areaName,@Param("parentId") Integer parentId);

    @Select("select * from t_area where parent_id=#{parentId} and del_flag=0")
    @ResultMap("AreaResult")
    List<Area> selectByParentId(@Param("parentId") Integer parentId);

    @Select("select * from t_area where area_name like concat(#{areaNamePrefix},'%') and parent_id=#{parentId} and del_flag=0")
    @ResultMap("AreaResult")
    List<Area> selectByAreaNamePrefixAndParentId(@Param("areaNamePrefix") String areaNamePrefix,@Param("parentId") Integer parentId);

    @Select("select * from t_area where parent_id=#{parentId} and area_name not like concat('%',#{exclude}) and del_flag=0")
    @ResultMap("AreaResult")
    List<Area> selectByParentIdAndExclude(@Param("parentId") Integer parentId,@Param("exclude") String excludeCondition);

    List<AreaLevel> selectAllUpAreaFourLevelVillage();

    AreaLevel selectAllUpAreaByVillageId(Integer villageId);

    AreaLevel selectAllUpAreaByCommunityId(Integer communityId);

    List<Area> selectGroupByThirdId(Integer thirdId);

    int batchUpdate(List<Area> AreaList);

    int batchUpdateLonLat(List<Area> AreaList);

    int batchInsert(List<Area> areaList);

    int batchDelete(List<Integer> list);

    int batchUpdateByParentId(List<Area> areas2);
}
